package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.dto.LifePageDto;
import com.example.entity.LifePlace;
import com.example.service.LifePlaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/admin/lifeplace")
public class LifePlaceController {
    @Autowired
    private LifePlaceService lifePlaceService;

    @GetMapping("/page")
    public Result<PageResult> page(LifePageDto lifePageDto) {
        PageResult page = lifePlaceService.page(lifePageDto);
        return Result.success(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody LifePlace lifePlace) {
        lifePlaceService.add(lifePlace);
        return Result.success();
    }

    @DeleteMapping("{dno}")
    public Result deleteByDno(@PathVariable String dno){
        lifePlaceService.deleteByDno(dno);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody LifePlace lifePlace){
        lifePlaceService.update(lifePlace);
        return Result.success();
    }
}
